<?php
class Privacy extends AppModel {

	var $name = 'Privacy';
	var $useTable = 'privacy';
	var $useDbConfig = 'users';

	//The Associations below have been created with all possible keys, those that are not needed can be removed
/**
	var $belongsTo = array(
			'User' => array('className' => 'User',
								'foreignKey' => 'user_id',
								'conditions' => '',
								'fields' => '',
								'order' => ''
			)
	);
*/


	function getData($uid) {
		$c = array('user_id'=>$uid);
		$f = $this->getFields();
		if (!$this->hasAny($c)) {
			$this->save($c);
		}
		return $this->find('first', array('conditons'=>$c, 'fields'=>$f));
	}

	function getSettingID($uid) {
		return $this->field('id', array('user_id'=>$uid));
	}

	function getPermition($uid) {
		$data = $this->getData($uid);	

		$p = array();
		foreach ($data['Privacy'] as $k => $v) {
			$p[$v][$k] = 1;
		}
		return $p;
	}

	function getFields() {
		$schema = $this->schema();
		unset($schema['id']);
		unset($schema['user_id']);
		return array_keys($schema);
	}

}
?>
